package com.zd.wechatPlatform.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zd.wechatPlatform.bean.model.WxClickMsg;
import com.zd.wechatPlatform.bean.model.WxFeebackMsg;
import com.zd.wechatPlatform.common.enums.StatusEnum;
import com.zd.wechatPlatform.dao.WxClickMsgDao;
import com.zd.wechatPlatform.dao.WxFeebackMsgDao;
import com.zd.wechatPlatform.dao.common.BaseDao;
import com.zd.wechatPlatform.dao.common.FindRequestEntity;
import com.zd.wechatPlatform.dao.common.OrderEnum;
import com.zd.wechatPlatform.dao.common.WhereEnum;
import com.zd.wechatPlatform.service.IWxClickMsgService;

@Service
public class WxClickMsgServiceImpl extends BaseServiceImpl<WxClickMsg> implements IWxClickMsgService {
	@Autowired
	private WxClickMsgDao WxClickMsgDao;

	@Autowired
	private WxFeebackMsgDao wxFeebackMsgDao;
	
	@Override
	public BaseDao<WxClickMsg> getBaseDao() {
		return WxClickMsgDao;
	}
	
	@Override
	public List<WxFeebackMsg> getClickMsg(Integer accountId, String eventKey) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("account_id", WhereEnum.EQ, accountId);
		findReq.addWhere("event_key", WhereEnum.EQ, eventKey);
		findReq.addWhere("status", WhereEnum.EQ, StatusEnum.valid.getKey());
		
		findReq.addOrder("seq", OrderEnum.ASC);
		
		List<WxClickMsg> clickMsgList = find(findReq);
		
		List<WxFeebackMsg> feebackMsgList = new ArrayList<>();
		if(clickMsgList != null && clickMsgList.size() > 0) {
			for(WxClickMsg clickMsg : clickMsgList) {
				feebackMsgList.add(wxFeebackMsgDao.get(clickMsg.getFeebackMsgId()));
			}
		}
		return feebackMsgList;
	}
}
